import { createRouter, createWebHistory } from "vue-router"
import { routes } from "./commonRoutes"
import { $Storage } from "@utils/storage.js"


const router = createRouter({
  history: createWebHistory(),
  routes,
})



router.beforeEach((to, from, next) => {
  // console.log(to.name)
  // console.log(from)
  // next()
  if (!$Storage.getItem("jwttoken") && (to.name !== "login")) {
    next("/login")
  } else {
    next()
  }
})

export const setUpRouter = (app) => {
  app.use(router)
}

export default router